/**
 * 
 */
package fr.gfi.agraf.vue.action.gerer.excel;

import java.io.File;
import java.util.List;

import fr.gfi.agraf.service.IImportService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.bean.LigneExcelImportBean;

/**
 * @author Fw
 * 
 */
public class ImportExcelAction extends AbstractApplicationSupportAction {

	/**
	 * Généré par Java
	 */
	private static final long serialVersionUID = -1679167236557067095L;

	private static final String IMPORT_SERVICE = "ImportService";

	public static final String LISTE_IMPORT_TO_VALIDE = "listeImportAValider";

	private static final String PROP_MSG_SUCCESS = "import.success";

	private static final String PROP_MSG_EMPTY = "import.success.empty";

	private File fileUploaded;

	private Long idPerimetre;

	@Override
	public String executeAction() throws Exception {

		// Récupere le service
		final IImportService importService = (IImportService) SpringFactory.getApplicationContext().getBean(
				IMPORT_SERVICE);

		final List<LigneExcelImportBean> listeRecup = importService.traiterImport(fileUploaded, idPerimetre,
				getUtilisateurConnecte().getId());
		sessionMap.put(LISTE_IMPORT_TO_VALIDE, listeRecup);

		if (listeRecup != null && listeRecup.size() > 0) {
			addActionMessage(PropertiesUtils.getProperty(PROP_MSG_SUCCESS));
		} else {
			addActionError(PropertiesUtils.getProperty(PROP_MSG_EMPTY));
		}

		return SUCCESS;
	}

	/**
	 * @param fileUploaded
	 *            the fileUploaded to set
	 */
	public void setFileUploaded(final File fileUploaded) {
		this.fileUploaded = fileUploaded;
	}

	/**
	 * @param idPerimetre
	 *            the idPerimetre to set
	 */
	public void setIdPerimetre(final Long idPerimetre) {
		this.idPerimetre = idPerimetre;
	}

}
